package com.edu.exam.entity.quality.monitoring;

import com.edu.exam.enums.PatrolDeliveryStatus;
import com.edu.exam.enums.PatrolNotificationStatus;
import com.edu.exam.enums.PatrolNotificationType;
import com.edu.exam.enums.PatrolPriorityLevel;
import com.edu.exam.enums.PatrolUrgencyLevel;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

/**
 * 巡考用户通知实体类
 *
 * 负责管理巡考相关的通知发送和接收
 * 根据E-05-巡考管理模块设计实现
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public class PatrolNotification {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "user_id", nullable = false)
    private Long userId;

    @Column(name = "user_name", length = 100)
    private String userName;

    @Column(name = "user_email", length = 200)
    private String userEmail;

    @Column(name = "user_phone", length = 20)
    private String userPhone;

    @Enumerated(EnumType.STRING)
    @Column(name = "type", nullable = false, length = 50)
    private PatrolNotificationType type;

    @Column(name = "title", nullable = false, length = 200)
    private String title;

    @Column(name = "content", nullable = false, columnDefinition = "TEXT")
    private String content;

    @Column(name = "related_task_id")
    private Long relatedTaskId;

    @Column(name = "related_record_id")
    private Long relatedRecordId;

    @Column(name = "related_violation_id")
    private Long relatedViolationId;

    @Column(name = "channels", columnDefinition = "TEXT")
    private String channels; // 通知渠道（JSON格式）

    @Column(name = "sent_time")
    private LocalDateTime sentTime;

    @Column(name = "read_time")
    private LocalDateTime readTime;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private PatrolNotificationStatus status = PatrolNotificationStatus.PENDING;

    @Column(name = "priority_level", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolPriorityLevel priorityLevel = PatrolPriorityLevel.NORMAL;

    @Column(name = "urgency_level", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolUrgencyLevel urgencyLevel = PatrolUrgencyLevel.LOW;

    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    @Column(name = "created_by", length = 100)
    private String createdBy;

    @Column(name = "scheduled_time")
    private LocalDateTime scheduledTime; // 计划发送时间

    @Column(name = "expiry_time")
    private LocalDateTime expiryTime; // 过期时间

    @Column(name = "retry_count")
    private Integer retryCount = 0; // 重试次数

    @Column(name = "max_retries")
    private Integer maxRetries = 3; // 最大重试次数

    @Column(name = "delivery_status", length = 20)
    @Enumerated(EnumType.STRING)
    private PatrolDeliveryStatus deliveryStatus = PatrolDeliveryStatus.PENDING; // 投递状态

    @Column(name = "delivery_details", columnDefinition = "TEXT")
    private String deliveryDetails; // 投递详情（JSON格式）

    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage; // 错误信息

    @Column(name = "response_required")
    private Boolean responseRequired = false; // 是否需要回应

    @Column(name = "response_deadline")
    private LocalDateTime responseDeadline; // 回应截止时间

    @Column(name = "user_response", columnDefinition = "TEXT")
    private String userResponse; // 用户回应

    @Column(name = "response_time")
    private LocalDateTime responseTime; // 回应时间

    @Column(name = "template_id")
    private String templateId; // 模板ID

    @Column(name = "template_params", columnDefinition = "TEXT")
    private String templateParams; // 模板参数（JSON格式）

    @Column(name = "attachments", columnDefinition = "TEXT")
    private String attachments; // 附件（JSON格式）

    @Column(name = "action_buttons", columnDefinition = "TEXT")
    private String actionButtons; // 操作按钮（JSON格式）

    @Column(name = "tracking_enabled")
    private Boolean trackingEnabled = false; // 是否启用跟踪

    @Column(name = "open_count")
    private Integer openCount = 0; // 打开次数

    @Column(name = "click_count")
    private Integer clickCount = 0; // 点击次数

    @Column(name = "first_open_time")
    private LocalDateTime firstOpenTime; // 首次打开时间

    @Column(name = "last_open_time")
    private LocalDateTime lastOpenTime; // 最后打开时间

    @Column(name = "device_info", columnDefinition = "TEXT")
    private String deviceInfo; // 设备信息（JSON格式）

    @Column(name = "location_info", columnDefinition = "TEXT")
    private String locationInfo; // 位置信息（JSON格式）

    @Column(name = "batch_id")
    private String batchId; // 批次ID

    @Column(name = "campaign_id")
    private String campaignId; // 活动ID

    @Column(name = "source_system", length = 100)
    private String sourceSystem = "PATROL_SYSTEM"; // 来源系统

    @Column(name = "external_id", length = 100)
    private String externalId; // 外部系统ID

    @Column(name = "locale", length = 10)
    private String locale = "zh_CN"; // 语言地区

    @Column(name = "timezone", length = 50)
    private String timezone = "Asia/Shanghai"; // 时区

    @Column(name = "archived")
    private Boolean archived = false; // 是否归档

    @Column(name = "archive_time")
    private LocalDateTime archiveTime; // 归档时间

    @Column(name = "tags", length = 500)
    private String tags; // 标签（逗号分隔）

    @Column(name = "metadata", columnDefinition = "TEXT")
    private String metadata; // 元数据（JSON格式）


}